#ifndef DATASETREADER_H
#define DATASETREADER_H

#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>


using namespace std;

template <class dataType>
class DataPair{

public:

	vector<dataType> inputs;
	vector<dataType> outputs;

	DataPair(){}
	~DataPair(){}

};


enum TYPE{
	INTEGER,
	DOUBLE
};



class DatasetReader{

public:
	static DatasetReader* getInstance() ;

	template <typename inputType>
	static  vector<DataPair<inputType>>& parseFile(string fileName,int,int,TYPE);	

	~DatasetReader();

protected:
	DatasetReader();

private:		
	void StringExplode(string str, string separator, vector<string>* results);

};

template <typename inputType>
vector<DataPair<inputType>>& DatasetReader::parseFile(string fileName, int inputPatternNum, int outputPatternNum, TYPE type){

	string line;
	stringstream *ss;
	DataPair<inputType> pair;
	int inputNum = 0 ;
	string temp;
	vector<string> lineTokens;

	static vector<DataPair<inputType>> datasets;
	datasets.clear();

	ifstream infile;
	infile.open(fileName.c_str());

	if(infile.good() && infile.is_open()){

		while(! infile.eof()){

			pair.inputs.clear ();
			pair.outputs.clear ();

			getline(infile, line);
			ss = new stringstream(line);
			for(int i = 0 ; i < inputPatternNum ; i++){
				*ss>>temp;
				if(type == INTEGER){
					pair.inputs.push_back(atoi(temp.c_str()));
				}
				else if(type == DOUBLE){
					pair.inputs.push_back(atof(temp.c_str()));
				}
				else;
				//
			}
			for(int i = 0 ; i < outputPatternNum ; i++){
				*ss>>temp;
				if(type == INTEGER){
					pair.outputs.push_back(atoi(temp.c_str()));
				}
				else if(type == DOUBLE){
					pair.outputs.push_back(atof(temp.c_str()));
				}
				else;
			}
			datasets.push_back(pair);
		}

	}else{

	}

	return datasets;
}

#endif